json

type json

A JSON (JavaScript Object Notation) datatype.

JSON values are created from text and support conversion to GTV via gtv.from_json(). They can be stored in the database as an entity attribute.

JSON values in Rell are represented internally with text, which has been validated as legal JSON.

Since

0.6.0

See also

Constructors

Link copied to clipboard
pure constructor(value: text)

Construct a JSON value from text.

Functions

Link copied to clipboard
pure function as_big_integer(): big_integer

Convert this JSON value to a big_integer.

All JSON values that can be converted to integer with as_integer() can also be converted to big_integer with as_big_integer(), though the reverse is not true, since big_integer values may fall outside the integer range.

Link copied to clipboard

Convert this JSON value to a big_integer.

All JSON values that can be converted to integer with as_integer_or_null() can also be converted to big_integer with as_big_integer_or_null(), though the reverse is not true, since big_integer values may fall outside the integer range.

Link copied to clipboard
pure function as_boolean(): boolean

Convert this JSON boolean value to a boolean.

Link copied to clipboard
pure function as_boolean_or_null(): boolean?

Convert this JSON boolean value to a boolean.

Link copied to clipboard
pure function as_integer(): integer

Convert this JSON integer value to an integer.

All JSON values that can be converted to integer with as_integer() can also be converted to big_integer with as_big_integer(), though the reverse is not true, since big_integer values may fall outside the integer range.

Link copied to clipboard
pure function as_integer_or_null(): integer?

Convert this JSON integer value to an integer.

All JSON values that can be converted to integer with as_integer_or_null() can also be converted to big_integer with as_big_integer_or_null(), though the reverse is not true, since big_integer values may fall outside the integer range.

Link copied to clipboard
pure function as_text(): text

Convert this JSON text value to text.

Note that this method is different to json.to_text(). This method retrieves this text-typed JSON value as Rell text, and throws an exception if this JSON value is not of text type. json.to_text() converts this entire JSON value to its text representation, regardless of what type of JSON value this is, and does not throw an exception.

Link copied to clipboard
pure function as_text_or_null(): text?

Convert this JSON text value to text.

Link copied to clipboard
pure function get(index: integer): json

Get the element at the specified index of this JSON array.

json_array.get(index) is equivalent to json_array[index].

pure function get(key: text): json

Get the member with the specified key in this JSON object.

json_object.get(key) is equivalent to json_object[key].

Link copied to clipboard
pure function get_or_null(index: integer): json?

Get the element at the specified index of this JSON array, or null if this JSON value is not an array, or if the specified index is out of bounds.

pure function get_or_null(key: text): json?

Get the member with the specified key in this JSON object, or null if this JSON value is not an object, or if the specified key is not found in this object.

Link copied to clipboard
pure function is_array(): boolean

Determine whether this JSON value is an array.

Link copied to clipboard
pure function is_big_integer(): boolean

Determine whether this JSON value can be converted to big_integer.

All JSON values that return true with is_integer() also return true with is_big_integer(), though the reverse is not the case, since big_integer values may fall outside the integer range.

Link copied to clipboard
pure function is_boolean(): boolean

Determine whether this JSON value is a boolean.

Link copied to clipboard
pure function is_integer(): boolean

Determine whether this JSON value is an integer.

All JSON values that return true with is_integer() also return true with is_big_integer(), though the reverse is not the case, since big_integer values may fall outside the integer range.

Link copied to clipboard
pure function is_null(): boolean

Determine whether this JSON value is null.

Link copied to clipboard
pure function is_object(): boolean

Determine whether this JSON value is an object.

Link copied to clipboard
pure function is_text(): boolean

Determine whether this JSON value is text.

Link copied to clipboard
pure function keys(): set<text>

Get the keys of this JSON object.

Link copied to clipboard
pure function size(): integer

Get the size of this JSON value; i.e. the number of elements in this JSON array, or the number of key-value pairs in this JSON object.

Link copied to clipboard
(alias) pure function str(): text

Convert this JSON value to text.

Note that this method is different to json.as_text(). This method converts this entire JSON value to its text representation, regardless of what type of JSON value this is, and does not throw an exception. json.as_text() retrieves this text-typed JSON value as Rell text, and throws an exception if this JSON value is not of text type.

Alias
Link copied to clipboard
pure function to_text(): text

Convert this JSON value to text.

Note that this method is different to json.as_text(). This method converts this entire JSON value to its text representation, regardless of what type of JSON value this is, and does not throw an exception. json.as_text() retrieves this text-typed JSON value as Rell text, and throws an exception if this JSON value is not of text type.